package com.hspedu.newData.dmsxl.链表.遍历;

import com.hspedu.newData.dmsxl.ds.ListNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-14 
 * @Version: 1.0
 */

public class LC876链表的中间结点 {
    public ListNode middleNode(ListNode head) {

        ListNode dummy = new ListNode(0,head);
        ListNode first = dummy;
        ListNode second = dummy;

        while (second != null && second.next != null){
            first = first.next;
            second = second.next.next;
        }

        if (second != null){
            first = first.next;
        }

        return first;
    }
}
